package com.hqyj.controller;

import com.hqyj.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.LinkedList;
import java.util.List;

/**
 * 项目:demo-springboot-230701
 * 描述:
 * 时间:2023/9/25 14:17
 * 作者:admin
 * 版本:1.0
 **/
@Controller
public class IndexController {

    @GetMapping("/")
    public String index(Model model){
        //从数据库查询出来的学生信息
        Student stu = new Student();
        stu.setId(1);
        stu.setName("张三");
        stu.setAge(22);
        //设置
        model.addAttribute("stu",stu);
        List<Student> list = new LinkedList<>();
        String[] address={"成都","南充","绵阳"};
        for (int i=0;i<3;i++){
            Student s = new Student();
            s.setId(i);
            s.setName("张三"+i);
            s.setAge(22+i);
            s.setAddress(address[i]);
            list.add(s);
        }
        model.addAttribute("list",list);
        return "index";
    }
}
